home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / isobuild / isobuild.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-11  |  7.8 KB  |  259 lines

  1.  
  2. /* isobuild.h */
  3.  
  4. /* This program implements the marching cubes surface tiler described by
  5.  * Lorensen & Cline in the Siggraph 87 Conference Proceedings.
  6.  *
  7.  *   Author:  Brian L. Tierney
  8.  *            Lawrence Berkeley Laboratory
  9.  *            Imaging Technologies Group
  10.  *            email: bltierney@lbl.gov
  11.  *
  12.  * Portions developed at the National Center for Supercomputing Applications at
  13.  * the University of Illinois at Urbana-Champaign.
  14.  * Written by Mike Krogh, NCSA, Feb.  2, 1990
  15.  *
  16.  */
  17.  
  18. /*   This program is copyright (C) 1991, Regents  of  the
  19. University  of  California.   Anyone may reproduce this software,
  20. in whole or in part, provided that:
  21. (1)  Any copy  or  redistribution  must  show  the
  22.      Regents  of  the  University of California, through its
  23.      Lawrence Berkeley Laboratory, as the source,  and  must
  24.      include this notice;
  25. (2)  Any use of this software must reference this  distribu-
  26.      tion,  state that the software copyright is held by the
  27.      Regents of the University of California, and  that  the
  28.      software is used by their permission.
  29.  
  30.      It is acknowledged that the U.S. Government has  rights
  31. to this software under  Contract DE-AC03-765F00098 between the U.S.
  32. Department of Energy and the University of California.
  33.  
  34.      This software is provided as a professional  academic  contribu-
  35. tion  for  joint exchange.  Thus it is experimental, is pro-
  36. vided ``as is'', with no warranties of any kind  whatsoever,
  37. no  support,  promise  of updates, or printed documentation.
  38. Bug reports or fixes may be sent to the author, who may or may
  39. not act on them as he desires.
  40. */
  41.  
  42. /* $Id: isobuild.h,v 1.5 1992/01/31 02:06:50 tierney Exp $ */
  43.  
  44. /* $Log: isobuild.h,v $
  45.  * Revision 1.5  1992/01/31  02:06:50  tierney
  46.  * *** empty log message ***
  47.  *
  48.  * Revision 1.4  1992/01/30  20:06:20  davidr
  49.  * prior to Brian
  50.  *
  51.  * Revision 1.3  1992/01/10  01:59:31  davidr
  52.  * works with triserv now
  53.  *
  54.  * Revision 1.2  1991/12/19  01:42:20  davidr
  55.  * added RCS identification markers
  56.  * */
  57.  
  58.  
  59. /*   #define SPEED */            /* show execution speed */
  60.  
  61. #include <stdio.h>
  62. #include <math.h>
  63. #include <sys/types.h>
  64. #include <hipl_format.h>
  65. #include <sys/time.h>
  66. #ifdef SPEED
  67. #include <sys/timeb.h>
  68. #endif
  69.  
  70. /*************************************************************/
  71. /* defines section */
  72. /* #define DEBUG */
  73. /* #define TESTING */
  74.  
  75.  
  76. /* define this for floating point input: no reason to do this in
  77.    most cases, it just uses more memory
  78. */
  79.  
  80. /*#define FLOAT_INPUT  *//* internal data set type float */
  81.  
  82. #define SHORT_NORMALS   /* see normal.c for explanation */
  83.  
  84. /* some usefull macros */
  85. #define Fread(a,b,c,d) fread((char *)(a), b, (int)(c), d)
  86. #define Calloc(x,y) (y *)calloc((unsigned)(x), sizeof(y))
  87. #define Fwrite(a,b,c,d) fwrite((char *)(a), b, (int)(c), d)
  88. #define Memset(a,b,c) memset((char *)(a), b, (int)(c))
  89.  
  90. /****************************************************************/
  91. #ifdef FLOAT_INPUT
  92. typedef float Data_type;
  93. #else
  94. typedef unsigned char Data_type;
  95. #endif
  96.  
  97. typedef unsigned char Grid_type;
  98.  
  99. /* Norm_type may be short or float */
  100. #ifdef FLOAT_INPUT
  101. typedef float Norm_type;
  102. #else
  103. #ifdef SHORT_NORMALS
  104. typedef short Norm_type;
  105. #else
  106. typedef float Norm_type;
  107. #endif
  108. #endif
  109.  
  110. typedef struct {
  111.     u_char       nverts;        /* possible values: 0-7 */
  112.     u_char       verts[8];
  113.     u_char       nedges;        /* possible values: 0-12 */
  114.     u_char       edges[12];
  115.     u_char       npolys;        /* possible values: 0-10 */
  116.     u_char       polys[30];    /* 10 polys * 3 vertices = 30 */
  117. }         CELL_ENTRY;
  118.  
  119. typedef struct {        /* structure for detecting regions to skip */
  120.     int       xloc, yloc;
  121.     int       width, height;
  122.     Data_type min, max;
  123.     Data_type **dslice;        /* pointer to a 2D data slice */
  124.     Grid_type **grid;        /* pointer to a 2D grid slice */
  125. }         BLOCK_INFO, *BINFO_PTR;
  126.  
  127. typedef struct norm {
  128.     Norm_type x, y, z;
  129. }         NORMAL_VECT;
  130.  
  131. /* output data structure */
  132. typedef struct plist {
  133.     u_char    x, y, z;
  134. /* CHANGE to something better -- davidr */
  135.     Norm_type nx, ny, nz;
  136. }         POINT, *POINT_PTR;
  137.  
  138. typedef struct vlist {
  139.     float     x, y, z;
  140. }         VERTEX, FLOAT_VECT, *VERT_PTR;
  141.  
  142. typedef struct norm_list {
  143.     Norm_type nx, ny, nz;
  144. }         NORMAL, *NORM_PTR;
  145.  
  146. typedef struct {        /* used to detect duplicate vertices */
  147.     int       edge_index;
  148.     int       num_edges;
  149. }         CUBE_TRIANGLES;
  150.  
  151. #ifdef MAIN
  152.  
  153. /*********************************************************************/
  154.  
  155.  /* set command line arguement defaults */
  156. char      MY_NAME[120];        /* name of this program (for error messages ) */
  157. int       PRE_NORMALS = 0;    /* pre-compute all normal values */
  158. Data_type TVAL = 50.;        /* threshold value */
  159. int       VERBOSE = 0;        /* print status messages */
  160. int       VERBOSE2 = 0;        /* print even more status messages */
  161. int       MARCH_NORMALS = 0;    /* compute vertex normals flag */
  162. int       OUTPUT_TYPE = 0;    /* type of output file: binary or ASCII */
  163. int       DIVIDING = 0;        /* marching or dividing cubes method */
  164. int       SERVER = 0;        /* run in server mode */
  165. int       DUP_CHECK = 1;    /* check for duplicate vertices */
  166. short     PORT_NUM = 10000;    /* socket port number for server */
  167. int       SEG_METHOD = 0;    /* data segmentation method: threshold (0) or
  168.                  * flood fill (1) */
  169. int       BRIDGE_TYPE = 3;    /* in flood_fill segmentation: check strength
  170.                  * of connecting bridges before continuing
  171.                  * the fill */
  172. int       SMOOTH_GRID = 0;    /* apply filter to smooth binary mask */
  173. int       SKIP_BLOCKS = 1;    /* create block min/max map for speed */
  174. int       SMALLER_BOX = 0;    /* flag indicating that the entire data set
  175.                  * is not being examined */
  176. int       BLOCK_SIZE = 0;    /* use xdim / 12  */
  177. int       DO_CUBE_CENTER_NORMALS = 1;  /* more accurate normals for dividing 
  178.                       cubes version */
  179. int       SMALL_CHUNKS = 1;     /* output is done in small chunks, not all 
  180.                    at once */
  181. int       SX = 0, SY = 0, SZ = 0;    /* starting and ending locations to
  182.                      * examine from the original data
  183.                      * set. */
  184. int       EX = 9999, EY = 9999, EZ = 9999;
  185.  
  186. char     *IN_FNAME = NULL;
  187. char     *OUT_FNAME = NULL;
  188. char     *OUT_MASK_FNAME = NULL;
  189. char     *IN_MASK_FNAME = NULL;
  190.  
  191. FILE     *poly_fp = NULL;
  192. FILE     *out_mask_fp = NULL;
  193. FILE     *in_mask_fp = NULL;
  194.  
  195.  
  196. /* global data /segmentation arrays */
  197.  
  198. Data_type ***data = NULL;    /* hold input data */
  199.  
  200. NORMAL_VECT ***normals = NULL;    /* holds normals */
  201. Grid_type ***grid = NULL;    /* segmentation grid */
  202. BLOCK_INFO **block_info_array = NULL;
  203. FLOAT_VECT **gradient_curr_slice=NULL, **gradient_next_slice=NULL;
  204.  
  205. int       xdim, ydim, zdim;    /* size of input data volume */
  206. int       xmax, ymax, zmax;    /* xmax = xdim -1, etc */
  207. int       num_blocks;        /* number of blocks in a slice */
  208.  
  209. /* minimum and maximun values in the input data set */
  210. Data_type data_min = 999999, data_max = 0;
  211.  
  212. /* used to eliminate duplicate verts */
  213. CUBE_TRIANGLES **prevslice = NULL, **currslice = NULL;
  214.  
  215. #else
  216.  
  217. extern char MY_NAME[];
  218. extern int PRE_NORMALS;
  219. extern int VERBOSE;
  220. extern int VERBOSE2;
  221. extern int MARCH_NORMALS;
  222. extern int OUTPUT_TYPE;
  223. extern int DIVIDING;
  224. extern int SEG_METHOD;
  225. extern int BRIDGE_TYPE;
  226. extern int SMALLER_BOX;
  227. extern short PORT_NUM;
  228. extern int SX, SY, SZ, EX, EY, EZ;
  229. extern Data_type TVAL;        /* threshold value */
  230. extern int SERVER;
  231. extern int SKIP_HOLES;
  232. extern int SKIP_BLOCKS;
  233. extern int BLOCK_SIZE;
  234. extern int DUP_CHECK;
  235. extern int    SMOOTH_GRID;
  236. extern int    SMALL_CHUNKS;
  237. extern int    DO_CUBE_CENTER_NORMALS;
  238.  
  239. extern char *IN_FNAME;
  240. extern char *IN_MASK_FNAME;
  241.  
  242. extern FILE *poly_fp;
  243. extern FILE *in_mask_fp;
  244. extern FILE *out_mask_fp;
  245.  
  246. extern Data_type ***data;
  247. extern NORMAL_VECT ***normals;
  248. extern Grid_type ***grid;
  249. extern BLOCK_INFO **block_info_array;
  250. extern FLOAT_VECT **gradient_curr_slice, **gradient_next_slice;
  251. extern int xdim, ydim, zdim, xmax, ymax, zmax, num_blocks;
  252.  
  253. extern Data_type data_min, data_max;
  254. extern CUBE_TRIANGLES **prevslice, **currslice;
  255.  
  256. #endif
  257.  
  258. void      Error(), Status(), exit_handler();
  259.